package com.wutianyi.controller.innvo;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wutianyi.module.company.Company;
import com.wutianyi.module.member.dataobject.MemberDO;
import com.wutianyi.module.services.CompanyServices;
import com.wutianyi.service.SecurityManager;

@Controller("InnovIndexController")
@RequestMapping(value = "/innov/index.do")
public class IndexController {
	
	@Autowired
	private CompanyServices companyServices;
	
	@Autowired
	private SecurityManager securityManager;
	
	private String viewName = "innov/index";
	
	@RequestMapping
	public ModelAndView execute(@ModelAttribute("member") MemberDO member) {
		
		ModelAndView modelAndView = new ModelAndView(getViewName());
		
		Company company = companyServices.getCompanyByCId(member.getCompanyId());
		
		modelAndView.addObject("company", company);
		
		return modelAndView;
	}
	
	public void setCompanyServices(CompanyServices companyServices) {
		this.companyServices = companyServices;
	}
	
	public String getViewName() {
		return viewName;
	}
	
	public void setViewName(String viewName) {
		this.viewName = viewName;
	}
	
	@ModelAttribute("member")
	public MemberDO getMember(HttpServletRequest request) {
		return securityManager.getMember(request);
	}
}
